package com.huaxin.device.models;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.huaxin.device.dto.enums.CircuitBreakerAction;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 断路器定时任务
 */
@Data
@TableName("circuit_breaker_schedules")
@EqualsAndHashCode(callSuper = true)
public class CircuitBreakerSchedule extends BaseModel {

    /**
     * 设备ID
     */
    @TableField(value = "device_id")
    @Schema(description = "设备ID", example = "d123e456-789a-bcde-f012-3456789abcde")
    private String deviceId;

    /**
     * 任务名称
     */
    @TableField(value = "schedule_name")
    @Schema(description = "任务名称", example = "工作日定时分闸")
    private String scheduleName;

    /**
     * 操作类型
     */
    @TableField(value = "action")
    @Schema(description = "操作类型", example = "open")
    private CircuitBreakerAction action;

    /**
     * 触发时间（时分秒）
     */
    @TableField(value = "trigger_time")
    @JsonFormat(pattern = "HH:mm:ss")
    @Schema(description = "触发时间", example = "08:00:00")
    private LocalTime triggerTime;

    /**
     * 重复周期（JSON数组，如：[1,2,3,4,5] 表示周一至周五）
     */
    @TableField(value = "repeat_days")
    @Schema(description = "重复周期（1-7，1=周日）", example = "[1,2,3,4,5]")
    private String repeatDays;

    /**
     * 是否启用
     * 0=禁用，1=启用
     * 默认禁用
     */
    @TableField(value = "is_enabled")
    @Schema(description = "是否启用", example = "1")
    private Boolean isEnabled = false;

    /**
     * 下一次触发时间
     */
    @TableField(value = "next_trigger")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "下一次触发时间", example = "2025-08-18 08:00:00")
    private LocalDateTime nextTrigger;

    /**
     * 组织家族ID
     */
    @TableField(value = "family_id")
    @Schema(description = "组织家族ID", example = "f3b2f8e1-4c5d-4e6f-8b2a-1c2d3e4f5a6b")
    private String familyId;
}